home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr11 / pdox693.zip / TI127.ASC < prev    next >
Text File  |  1993-02-23  |  8KB  |  265 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Paradox                                NUMBER  :  127
  9.   VERSION  :  All
  10.        OS  :  DOS
  11.      DATE  :  February 23, 1993                        PAGE  :  1/4
  12.  
  13.     TITLE  :  Normalizing a Non-normalized Paradox Table
  14.  
  15.  
  16.  
  17.  
  18.   This Technical Information sheet demonstrates the best
  19.   interactive method for converting a non-normalized table into a
  20.   table in the first normal form.  In brief, a non-normalized table
  21.   is one in which repeating groups of information are spread out
  22.   over many fields, rather than placing them into a few fields with
  23.   many records.  For example, suppose you have a table which tracks
  24.   orders placed by a number of customers over a single year.  We
  25.   want this table to display the customer number and the number of
  26.   products purchased for each month.  For simplicity's sake, assume
  27.   the year only has three months (January, February, and March).
  28.  
  29.   Below is the non-normalized version of this table (OrdersA):
  30.  
  31.   OrdersA═╦═Customer #═╦═January═╦═February═╦═March═╗
  32.           ║   0001     ║   3     ║   7      ║   0   ║
  33.           ║   0002     ║   0     ║   1      ║   0   ║
  34.           ║   0003     ║   0     ║   0      ║  14   ║
  35.  
  36.   Below is the normalized version (the table is called OrdersB):
  37.  
  38.   OrdersB═╦═Customer #═╦═══Month═══╦═Quantity═╗
  39.           ║   0001     ║ January   ║      3   ║
  40.           ║   0001     ║ February  ║      7   ║
  41.           ║   0001     ║ March     ║      0   ║
  42.           ║   0002     ║ January   ║      0   ║
  43.           ║   0002     ║ February  ║      1   ║
  44.           ║   0002     ║ March     ║      0   ║
  45.           ║   0003     ║ January   ║      0   ║
  46.           ║   0003     ║ February  ║      0   ║
  47.           ║   0003     ║ March     ║     14   ║
  48.  
  49.   The first table is keyed on Customer # only.  All information
  50.   related to a single customer is stored in a single record with
  51.   many fields.  The second table is keyed on both Customer # and
  52.   Month.  Each customer has three records (twelve if we were
  53.   dealing with a full year), one for each month, and that month's
  54.   corresponding quantity.  It is necessary to perform a query or
  55.   possibly a series of queries to convert the data from the first
  56.   table to the normalized format of the second table.  To begin the
  57.   process, create a new table with the proper structure (one
  58.   structured like the OrdersB table).  Once this is done, set up
  59.   the query as shown on the next page:
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Paradox                                NUMBER  :  127
  75.   VERSION  :  All
  76.        OS  :  DOS
  77.      DATE  :  February 23, 1993                        PAGE  :  2/4
  78.  
  79.     TITLE  :  Normalizing a Non-normalized Paradox Table
  80.  
  81.  
  82.  
  83.  
  84.   Bring up the tables, OrdersA and OrdersB, with <F10> Ask
  85.  
  86.   OrdersA═╦═Customer #═╦═January═╦═February═╦═March═══╗
  87.           ║ _Cust      ║ _Quant1 ║          ║         ║
  88.           ║ _Cust      ║         ║ _Quant2  ║         ║
  89.           ║ _Cust      ║         ║          ║ _Quant3 ║
  90.  
  91.  
  92.   OrdersB═╦═Customer #═╦═══Month═══╦═Quantity═╗
  93.   Insert  ║ _Cust      ║ January   ║ _Quant1  ║
  94.   Insert  ║ _Cust      ║ February  ║ _Quant2  ║
  95.   Insert  ║ _Cust      ║ March     ║ _Quant3  ║
  96.  
  97.   In the query forms above, example elements are represented by an
  98.   underscore "_" preceding the label of the example element (i.e.
  99.   _Cust and _Quant1).  Example elements are created by pressing the
  100.   <F5> key and then typing a label for the example element.  On row
  101.   1, the insert query links the OrdersA Customer # field to the
  102.   OrdersB Customer # field (by the example element Cust) and the
  103.   OrdersA January Quantity field to the OrdersB Quantity field (by
  104.   the example element Quant1).  On row 2, the OrdersA Customer #
  105.   field is linked to the OrdersB Customer # field (by the example
  106.   element Cust) and the OrdersA February Quantity field is linked
  107.   to the OrdersB Quantity field (by the example element Quant2).
  108.   Use a new row for each field from the source that is being
  109.   inserted into the single target field.  For example, if the table
  110.   has a full year (twelve months), then the query would have twelve
  111.   rows of links.  The example element representing the quantity
  112.   must be different for each line in the query.  In this example we
  113.   chose to number them (i.e. Quant1, Quant2, Quant3).  The key word
  114.   "Insert" tells Paradox to insert new records in the OrdersB table
  115.   by copying the data from the OrdersA fields which contain example
  116.   elements (i.e. Cust and Quant1) to their corresponding fields in
  117.   OrdersB.
  118.  
  119.   Paradox versions 3.x and earlier allow a maximum of 22 lines in a
  120.   query form.  Version 4.0 allows a maximum of 64 lines.  If you
  121.   require more lines in a query form than is allowed by Paradox,
  122.   then break up the query form into two or more parts and save the
  123.   queries with different names using Scripts | QuerySave.  Each
  124.   script must be played to complete the entire query operation
  125.   using Scripts | Play.
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  Paradox                                NUMBER  :  127
  141.   VERSION  :  All
  142.        OS  :  DOS
  143.      DATE  :  February 23, 1993                        PAGE  :  3/4
  144.  
  145.     TITLE  :  Normalizing a Non-normalized Paradox Table
  146.  
  147.  
  148.  
  149.  
  150.   In the previous example, if Paradox only allowed 2 lines in a
  151.   query form, then it would be necessary to break up the query into
  152.   two parts as shown below:
  153.  
  154.   Query #1
  155.  
  156.   OrdersA═╦═Customer #═╦═January═╦═February═╦═March═╗
  157.           ║ _Cust      ║ _Quant1 ║          ║       ║
  158.           ║ _Cust      ║         ║ _Quant2  ║       ║
  159.  
  160.   OrdersB═╦═Customer #═╦═══Month═══╦═Quantity═╗
  161.   Insert  ║ _Cust      ║ January   ║ _Quant1  ║
  162.   Insert  ║ _Cust      ║ February  ║ _Quant2  ║
  163.  
  164.  
  165.   Query #2
  166.  
  167.   OrdersA═╦═Customer #═╦═January═╦═February═╦═March══╦
  168.           ║ _Cust      ║         ║          ║ _Quant1║
  169.  
  170.   OrdersB═╦═Customer #═╦═══Month═══╦═Quantity═╗
  171.   Insert  ║ _Cust      ║ March     ║ _Quant1  ║
  172.  
  173.  
  174.   Notes:
  175.  
  176.      1.  This is a generic example, however, the concept is
  177.          applicable to any database in which the repeating fields
  178.          contain the same type of data.
  179.  
  180.      2.  After setting up the query, save it with Scripts |
  181.          QuerySave.  To process the query, first clear all images
  182.          off the screen with <Alt-F8>, then play the querysave
  183.          script and press <F2>.  The method outlined in this
  184.          Technical Information sheet enables you to use a non-
  185.          normalized table for data-entry purposes and to create a
  186.          query to quickly convert the data to a normalized version
  187.          for reporting purposes.
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.   PRODUCT  :  Paradox                                NUMBER  :  127
  207.   VERSION  :  All
  208.        OS  :  DOS
  209.      DATE  :  February 23, 1993                        PAGE  :  4/4
  210.  
  211.     TITLE  :  Normalizing a Non-normalized Paradox Table
  212.  
  213.  
  214.  
  215.  
  216.      3.  For further discussion of the theory behind normalization,
  217.          refer to Technical Information sheet 124.  For additional
  218.          information about queries, refer to Chapter 5 and 6 of the
  219.          Paradox 4.0 User's Guide (for versions earlier than 4.0,
  220.          refer to Chapter 4 of the Paradox User's Guide).
  221.  
  222.   DISCLAIMER: You have the right to use this technical information
  223.   subject to the terms of the No-Nonsense License Statement that
  224.   you received with the Borland product to which this information
  225.   pertains.
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.